using UnityEngine;

public class SPR_Parallax : MonoBehaviour
{
	private float length;

	private float height;

	private Vector2 startpos;

	private GameObject Camera;

	[Header("0 - 1 | Higher the number the more distance from camera")]
	public float HorizontalParallaxAmount;

	public float VerticalParallaxAmount;

	public bool backgroundLoop;

	private void Start()
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		Camera = ((Component)CameraManager.instance).gameObject;
		startpos = Vector2.op_Implicit(((Component)this).transform.position);
		if (Object.op_Implicit((Object)(object)((Component)this).GetComponent<SpriteRenderer>()))
		{
			Bounds bounds = ((Renderer)((Component)this).GetComponent<SpriteRenderer>()).bounds;
			length = ((Bounds)(ref bounds)).size.x;
			bounds = ((Renderer)((Component)this).GetComponent<SpriteRenderer>()).bounds;
			height = ((Bounds)(ref bounds)).size.y;
		}
		else
		{
			length = 1f;
			height = 1f;
			Debug.LogWarning((object)"Unable to find SpriteRenderer in SPR_Parallax object, defaulting to length/height = 1");
		}
	}

	private void LateUpdate()
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		float num = Camera.transform.position.x * (1f - HorizontalParallaxAmount);
		float num2 = Camera.transform.position.x * HorizontalParallaxAmount;
		float num3 = Camera.transform.position.y * (1f - VerticalParallaxAmount);
		float num4 = Camera.transform.position.y * VerticalParallaxAmount;
		((Component)this).transform.position = new Vector3(startpos.x + num2, startpos.y + num4, ((Component)this).transform.position.z);
		if (backgroundLoop)
		{
			if (num > startpos.x + length)
			{
				startpos.x += length;
			}
			else if (num < startpos.x - length)
			{
				startpos.x -= length;
			}
			if (num3 > startpos.y + height)
			{
				startpos.y += height;
			}
			else if (num3 < startpos.y - height)
			{
				startpos.y -= height;
			}
		}
	}
}
